<style>
</style>
<template>
  <list_url ref="list_url" :config="config">
    <template v-slot:news_item="{row}">
      <div class="flex" v-for="v in row.news_item" style="width: 100%;align-items: center;">
        <img style="width: 30px;height: 30px;" :src="v.thumb_url" referrerpolicy="no-referrer">
        <a class="text-ellipsis max" style="display: block;" target="_blank" :href="v.url">{{v.title}}</a>
        <p class="text-ellipsis max">{{v.digest}}</p>
      </div>
    </template>
    <template #action="{row}">
      <el-button @click="to_edit(row)" size="small">详情</el-button>
    </template>
  </list_url>
</template>
<script>
import {iframe, in_right_admin} from "@/js/tool.js";
import {ajax} from "@/js/api_tool.js";
import {_config} from "@/js/s94_tool.js";
import s94Mjs from "s94-js";

export default {
  props: ['__iframe'],
  data(){
    let app = this, btns = {}, is_del = this.$get('is_del');

    if(in_right_admin('WechatArticle/publish_delete')) btns['彻底删除'] = function(){
      let ids = app.$refs['list_url'].selected_ids.join(',');
      if (!ids) return
      ajax({url:'/admin/wechat_article/publish_delete?ids='+ids, loading:true});
    }
    let forms_config = {};
    let list_cols = {
      id: {name:'id', label:'article_id', width:'600px', fixed:'left'},
      news_item: {name:'news_item', label:'图文详情', type:'news_item', min_width:'250px'},
    };

    return {
      config: {
        api: '/admin/wechat_article/publish_'+(is_del?'recycle':'list'),
        title: "已发布文章列表"+(is_del?'(已删除)':''),
        btns: btns,
        forms_config: forms_config,
        list_cols: list_cols,
        resdata: function(list){
          return list;
        },
        limit: 20,
        p: this.$get('p', 1),
      },
    }
  },
  methods: {
    to_edit(row){
      let can_edit = in_right_admin('WechatArticle/edit') && ~[0,row.tenant_id].indexOf(_config('this_tenant.id'))
      let param = {
        id: row.id,
      }
      if (!can_edit) param['is_info'] = 1;
      iframe('wechat_article/edit?'+s94Mjs.param_encode(param))
    },
  },
  mounted() {
    let app = this;
    if (!this.__iframe) window['app'] = this;

  }
}
</script>
